package wvtool;

import com.google.common.base.Charsets;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.io.CharSink;
import com.google.common.io.CharSource;
import com.google.common.io.Files;
import weka.core.Attribute;
import weka.core.Instances;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;

/**
 * 作者: LDL
 * 功能说明:
 * 创建日期: 2015/6/18 15:25
 */
public class TextDirectoryToArff {

    public static void main(String[] args) throws IOException {

        CharSource source = Files.asCharSource(new File("D:/data/wordlist.txt"), Charsets.UTF_8);
        ImmutableList<String> lines = source.readLines();
        ArrayList<Attribute> atts = new ArrayList<Attribute>();
        //添加类别
        atts.add(new Attribute("class", Lists.newArrayList("10", "13", "16")));
        //添加各个词作为属性
        for (String line : lines){
            atts.add(new Attribute(line));
        }

        Instances dataset = new Instances("datasettest", atts, 1);
        CharSink sink = Files.asCharSink(new File("d:/data/test.arff"),Charsets.UTF_8);
        sink.write(dataset.toString());

        /*source = Files.asCharSource(new File("D:/data/wv.txt"), Charsets.UTF_8);
        ImmutableList<String> vectorlines = source.readLines();
        String line = vectorlines.get(0);
        List<String> list = Lists.newArrayList(Splitter.on(" ").trimResults().splitToList(line));
        String type = "0:"+list.get(list.size()-1);
        list.remove(0);
        list.add(0,type);
        list.remove(list.size()-1);

        String d = "{"+Joiner.on(",").join(list)+"}".replaceAll(":"," ");
        String f = d.replaceAll(":"," ");
        System.out.println(d);*/
    }
}
